/*
 * 		Author : Xerxes
 * 		Program: 
 * 		Created On : 02.10.2011 13:48:57 BDT
 *      "I have not failed, I have just found 10000 ways that won't work.
 * 
*/


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define tp pair< int, pair<int,int> >
#define mmk( x, y , z ) mk( x, mk( y, z ) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}

int N,E;
int K=1;
map< string, int > id;
map< int , string> revid;
vector< VI > path,_path;

int seen1[ 100 ];
int seen2[ 100 ];

inline void _SET(){
		
		id.clear();
		revid.clear();
		path.assign( N+5, VI() );
		_path.assign( N+5, VI() );
		SET(seen1,-1);
		SET(seen2,-1);
		
}

inline void Read(){
		_SET();
		vector< pair<string,string > > vi;
		string s1,s2;
		int x=0;
		fo(i,0,E){
			cin>>s1>>s2;
			vi.pb( mk(s1,s2) );
			if( id.count( s1 )  < 1 ){
				id[s1]=x;
				revid[x]=s1;
				++x;
			}
			if( id.count( s2 )  < 1 ){
				id[s2]=x;
				revid[x]=s2;
				++x;
			}
		}
		
		fo(i,0,E){
			int u = id[ vi[i].f ];
			int v = id[ vi[i].s ];
			
			path[u].pb(v);
			_path[v].pb(u);
		}
}
inline void dfs1(int father, stack< int > &nodes){
	if( seen1[ father ]==-1 ){
		seen1[ father ] = 0;
		VI cango = path[father];
		for(int i=0, j=SZ(cango) ; i<j; ++i ){
			dfs1( cango[i], nodes );
		}	
		nodes.push( father );
	}
}
inline void dfs2(int father, string ss){
	if( seen2[ father ] == -1 ){
		seen2[ father ] = 0;
		cout<<ss<< revid[father];
		VI cango = _path[father];
		for(int i=0,j=SZ(cango); i<j; ++i ){
			dfs2( cango[i],", " );
		}
	}
}
inline void Proc(){

	stack<int> nodes;	
	fo(i,0,N){
		if( seen1[i]==-1 ){
			dfs1( i, nodes );
		}
	}
	
	if( K!=1 ){
		printf("\n");
	}
	printf("Calling circles for data set %d:\n",K);
	while( nodes.empty()==false ){
		
		int father = nodes.top();
		nodes.pop();
		if( seen2[father]==-1 ){
			dfs2( father,"" );
			cout<<"\n";
		}
	}
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in","rt",stdin);
    #endif
    while( scanf("%d %d",&N,&E)==2 ){
		if( N==0 && E==0 )break;
		Read();
		Proc();
		++K;
	}

return 0;
}


